/***************************************************************************
 *   Copyright (C) 2009 by Marian Skvarek   *
 *   skvarek.marian@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef EASYSCORE_CORECNOTEGROUP_H
#define EASYSCORE_CORECNOTEGROUP_H

#include "CSymbol.h"
#include "CPositionList.h"
#include "CNoteGroupTablature.h"

#include <QLinkedList>

namespace easyscore
{
	namespace core
	{

		class CNoteGroupView;
		class CBar;
		class CNote;
		class CPause;

		/**
		Represents a set of notes that are played by an instrument at the same time

			@author Marian Skvarek <skvarek.marian@gmail.com>
		*/
		class CNoteGroup : public CSymbol
		{

//Members
			protected:
				QLinkedList<CNote *> mNotes;
				CNote *mTemporaryNote;
                                CPositionList mPositionList;
                                CNoteGroupTablature mTab;
				
				CNoteGroupView *mView;

//Accessors
			public:		
				QLinkedList< CNote * > &getNotes() { return mNotes; }		
				CNote* getTemporaryNote() const { return mTemporaryNote; }
                                CPositionList getPositionList() { updatePositionList(); return mPositionList; }
                                CNoteGroupTablature getTab() { return mTab; }
				
				CSymbolView *getView() { return (CSymbolView *) mView; }

//Constructors & Initialization
			public:
				CNoteGroup();
				void initialize();
				
				void clear();
				~CNoteGroup();
				
//Overrides
			public:
                                bool isNoteGroup() { return true; }
				
//Public methods
			public:
				int getNoteCount() { return mNotes.count(); }
				CNote *insertNote(int pitch);
                                void removeNote( CNote *note);
				CNote *getHighestNote();
				CNote *getLowestNote();
                                CNote *getByPosition(NOTE_POSITION pos);
				bool hasTemporaryNote() { return mTemporaryNote != 0; }
				void insertTemporaryNote(int pitch);
				void deleteTemporaryNote();
				void confirmTempraryNote();

                                void setTablature(FRETBOARD_POSITION position);
				
				bool hasView() { return mView != 0; }
				CSymbolView *getSymbolView() { return (CSymbolView *) mView; }
				void createView();
				void destroyView();	
				
//Protected methods
			protected:
                                void updatePositionList();
                                NOTE_PITCH nextString(NOTE_PITCH string);
                                STRING_NAME fromPitch(NOTE_PITCH stringPitch);

                                void updateView();

		};
	}
}

#endif
